<template>
    <div class="tixian">
        <van-nav-bar title="提现" left-arrow @click-left="onClickLeft" />
        <div class="top">
            <van-cell title="提现至" is-link :value="checked" @click="show = true" />
            <!-- <div class="left">提现至</div>
            <div class="right">中国银行(2345)
                <span class="icon"><van-icon name="arrow" /></span>
            </div> -->
        </div>
        <div class="mid">
            <div class="tit">
                <div class="num">提现金额</div>
                <div class="list">提现记录<van-icon name="arrow" />
                </div>
            </div>
            <div class="content">
                <!-- <van-field label="¥" v-model="number" type="number" /> -->
                <van-field label="¥" type="number" v-model="number">
                    <!-- <template #value>980.00</template> -->
                    <template #extra>全部提现</template>
                </van-field>
                <!-- <a>全部提现</a> -->
            </div>
            <div class="tips">
                平台提现规则为:每周工作日下午4点前可以提现，一周能提现一次(100起提)
            </div>
        </div>
        <van-button @click="onClickBtn">提交申请</van-button>
    </div>
    <van-action-sheet v-model:show="show" description="请选择提现方式" cancel-text="取消" close-on-click-action
        @cancel="onCancel" @select="onSelect">
        <!-- <van-action-sheet v-model:show="show" :actions="actions" cancel-text="取消" close-on-click-action @cancel="onCancel"
        @select="onSelect"> -->
        <!-- <div class="content">请选择提现方式</div> -->
        <van-radio-group v-model="checked" @change="onClickChange">
            <van-cell-group inset>
                <van-cell :title="item.name" :key="item.number" v-for="item in actions" :label="item.number" clickable
                    @click="checked = item.name">
                    <template #right-icon>
                        <van-radio :name="item.name" />
                    </template>
                </van-cell>
                <!-- <van-cell title="添加银行卡" clickable>
                </van-cell> -->
            </van-cell-group>
        </van-radio-group>

    </van-action-sheet>
</template>

<script lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router';
import { WithdrawCreate, WithdrawList, WithdrawWdInfo } from '../../../api/index';
import { Toast } from 'vant';
import router from '../../../router';
export default {
    name: "tuxian",
    setup() {
        let formData = new FormData();
        const route = useRoute();
        const number = ref('');
        // 定义onClickLeft方法
        const onClickLeft = () => history.back();
        const moneytype: any = ref(3)
        const show = ref(false);

        const checked = ref('微信');
        const actions = ref([]);
        const onSelect = (item) => {
            // 默认情况下点击选项时不会自动收起
            // 可以通过 close-on-click-action 属性开启自动收起
            show.value = false;
            checked.value = item.name;
        };
        const onCancel = () => Toast('取消');
        const onClickChange = (name: string) => {
            show.value = false;
            checked.value = name;
            console.log(name)
        };

        // 如果需要在组件挂载后执行某些操作，可以使用onMounted
        onMounted(() => {
            // 组件挂载后的逻辑
            moneytype.value = route.params.id
            WithdrawWdInfo(formData).then(res => {
                console.log(res);
                if (res.code == 1) {
                    // console.log(res)
                    checked.value = res.data[0].name
                    actions.value = res.data;
                } else {
                    Toast(res.msg)
                }
            })
            formData = new FormData();
        });
        const findReamrkByName = (actions, name) => {
            const action = actions.find(item => item.name === name);
            return action ? action.reamrk : null;
        };
        const onClickBtn = () => {
            console.log(findReamrkByName(actions.value, checked.value))
            formData.append("money", number.value)
            formData.append("moneytype", moneytype.value)
            formData.append("remark", findReamrkByName(actions.value, checked.value))
            WithdrawCreate(formData).then(res => {
                if (res.code == 1) {
                    console.log(res)
                    Toast(res.msg)
                    number.value = ""
                } else {
                    Toast(res.msg)
                }
            })
            formData = new FormData();
        }
        const router = useRouter();

        return {
            onClickLeft, onClickBtn, number, show,
            actions,
            onSelect, checked, onCancel, onClickChange
        };
    }
}
</script>

<style scoped lang="less">
.tixian {
    background: #F6F7F9;
    width: 100%;
    height: 100vh;

    .van-nav-bar {
        height: 52px;
    }

    .top {
        margin: 15px;
        height: 56px;
        background: #FFFFFF;
        border-radius: 7px 7px 7px 7px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        // padding: 20px;
        box-sizing: border-box;
        font-size: 16px;
        color: #3D3D3D;
        position: relative;


        :deep(.van-cell__title) {
            text-align: left;
        }
    }



    .van-button {
        width: 329px;
        height: 42px;
        background: linear-gradient(143deg, #0A84FF 0%, #0A7EF3 100%);
        border-radius: 347px 347px 347px 347px;
        font-size: 14px;
        color: #FFFFFF;
    }
}

.mid {
    margin: 15px;
    height: 150px;
    background: #FFFFFF;
    border-radius: 7px 7px 7px 7px;
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    box-sizing: border-box;
    padding: 20px;
    font-size: 14px;
    color: #3D3D3D;
    padding-bottom: 8px;

    .tit {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .list {
            display: flex;
            align-items: center;
            justify-content: space-between;

            span {
                display: block;
            }
        }
    }

    .content {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 16px;
        color: #3D3D3D;
        border-bottom: 1px solid #EBEBEB;


        .van-field {
            padding: 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        :deep(.van-field__label) {
            width: auto;
            padding-top: 10px;
        }

        :deep(.van-field__body) {
            font-size: 30px;
            color: #3D3D3D;
        }

        a {
            white-space: nowrap;
        }
    }

    .tips {
        font-size: 12px;
        color: #666666;
        text-align: left;
    }


}



:deep(.van-nav-bar__left .van-badge__wrapper) {
    color: #272635;
}

:deep(.van-cell__title) {
    text-align: left;
}
</style>
<style lang="less">
:deep(.van-action-sheet__content) {
    .content {
        font-size: 16px;
        color: #3D3D3D;
    }
}
</style>